package sunbao.ido.experimentalField.oom;

import java.util.ArrayList;
import java.util.List;

/**
 * \* User: MeiZhongHao
 * \* Date: 2018-11-10
 * \* Time: 15:33
 * \* Description:
 * \
 */
public class OomTest {

    /***
     *  设置内存大小    设置dump文件目录                                        设置GC日志目录
     *  -Xmx64m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=F:/logs/  -Xloggc:F:/logs/gc/gc.log
     * @param args
     */
    public static void main(String[] args) {
        List<BigObject> list = new ArrayList<>();
        for (int i = 0; ; i++) {
            // 测试youngGC
            new BigObject();
            // 测试FullGC
            list.add(new BigObject());
            if (i % 1000 == 0) {
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                }
            }
        }
    }
}

class BigObject {
    private char[] chars = new char[1024];
}